const {
  $util,
} = getApp();
Page({

  data: {
    isRecorder: false,
    recoder: '',
  },
  onLoad: function (opt) {
    wx.setNavigationBarTitle({
      title: '添加会议记录',
    });
    this.setData({
      id: opt.id,
      isRecorder: opt.isRecorder || false,
      recoder: decodeURIComponent(opt.recoder) || '',
    });
    this.checkRecording(opt.id);
  },
  checkRecording(id) {
    $util.request({
      url: 'entry/wxapp/partylife.sessions.getmeetrecord',
      data: {
        id,
      },
      success: (res) => {
        this.setData({
          detail: res.data,
          recordImgs: res.data.recordpic,
          imgs: res.data.image,
          meetingContent: res.data.record,
          recordTxt: res.data.recorddetail,
        });
      },
    });
  },
  /**
   * 会议记录
   */
  setMeetingContent(e) {
    this.setData({
      meetingContent: e.detail.value,
    });
  },
  bindRecodeVal(e) {
    this.setData({
      recordTxt: e.detail.value,
      recordVal: e.detail.value.trim(),
    });
  },
  recoderImgsChange(e) {
    this.setData({
      recordImgs: e.detail,
    });
  },
  imgsOnChange(e) {
    this.setData({
      imgs: e.detail,
    });
  },
  upload() {
    const {
      id,
      meetingContent,
      imgs,
    } = this.data;
    if (!meetingContent || meetingContent === '') {
      wx.showModal({
        title: '提示',
        content: '请填写会议记录',
        showCancel: false,
      });
      return;
    }

    if (!imgs || imgs.length === 0) {
      wx.showModal({
        title: '提示',
        content: '请选择会议图片',
        showCancel: false,
      });
      return;
    }
    $util.request({
      url: 'entry/wxapp/partylife.sessions.setmeetupload',
      data: {
        id,
        record: meetingContent,
        image: imgs,
      },
      success: () => {
        wx.showToast({
          title: '提交成功',
          mask: true,
          icon: 'success',
          duration: 1500,
        });
        setTimeout(() => {
        let pages = getCurrentPages();
        let prevPage = pages[pages.length - 2];
        prevPage.getInfo();
        wx.navigateBack();
        }, 1500);
      },
    });
  },
  recorderMeeting() { // 记录员上传会议记要
    const {
      recordTxt,
      recordImgs,
    } = this.data;
    if (recordTxt.trim() === '') {
      wx.showModal({
        title: '提示',
        content: '请填写会议纪要',
        showCancel: false,
      });
      return;
    }
    if (recordImgs.length === 0) {
      wx.showModal({
        title: '提示',
        content: '请选择会议图片',
        showCancel: false,
      });
      return;
    }
    $util.request({
      url: 'entry/wxapp/partylife.sessions.setmeetrecord',
      data: {
        record: recordTxt,
        image: recordImgs,
        id: this.data.id,
      },
      showLoading: false,
      success: (res) => {
        wx.showToast({
          title: '提交成功',
          mask: true,
          icon: 'none',
          duration: 1e3,
        });
        let pages = getCurrentPages();
        let prevPage = pages[pages.length - 2];
        prevPage.getInfo();
        wx.navigateBack();
      },
    });
  },
});